package com.jane.addressbook.servlet;

import java.io.IOException;
import java.sql.Connection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jane.addressbook.bean.Addressbook;
import com.jane.addressbook.jdbc.DBConnection;
import com.jane.addressbook.manager.AddressbookManager;

public class Edit extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 502450903960022686L;

	public void doGet(HttpServletRequest req, HttpServletResponse resp)  
            throws ServletException, IOException {  
          
        this.doPost(req, resp);  
    }  
  
      
    public void doPost(HttpServletRequest req, HttpServletResponse resp)  
            throws ServletException, IOException {
    	Connection conn = DBConnection.getConnection();
    	AddressbookManager manager = new AddressbookManager(conn); 
    	int id = Integer.parseInt(req.getParameter("id"));
    	Addressbook ab = manager.queryById(id);
    	
    	req.setAttribute("addressbook", ab);
		req.getRequestDispatcher("/addOrUpdate.jsp").forward(req, resp);
		DBConnection.closeConnection(conn);
    }
}
